import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class ButtonPlacerPanel extends JPanel {

	private BufferedImage my_image;

	public ButtonPlacerPanel() {
		super();
		try {

			my_image = ImageIO.read(new File("src/world map.jpg"));
			setSize(my_image.getWidth(), my_image.getHeight());

			JButton b = new JButton("HELLO");
			b.addMouseMotionListener(new DraggingButtonListener(b));
			add(b);

		} catch (IOException e) {
		}

	}

	private class DraggingButtonListener extends MouseMotionAdapter {
		private final JButton my_button;

		private DraggingButtonListener(JButton the_button) {
			my_button = the_button;
		}

		public void mouseDragged(MouseEvent the_e) {
			my_button.setLocation(the_e.getX() + my_button.getX(), the_e.getY() + my_button.getY());
			repaint();
		}

	}

	public void paint(final Graphics g) {
		g.drawImage(my_image, 0, 0, null);
	}

	public static void main(String args[]) {
		JFrame f = new JFrame();
		JPanel bpp = new ButtonPlacerPanel();
		f.add(bpp);
		f.setSize(bpp.getWidth(), bpp.getHeight());
		f.setTitle("Place the buttons");
		f.setResizable(false);
		f.setVisible(true);
	}

}
